﻿@model CNRegex.Web.Models.ModelRegexHome

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/css/RegexHomeIndex.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.cookie.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/common.js")" type="text/javascript"></script>
<script type="text/javascript">
	function search() {
		var keyWords = jQuery.trim($("#txtKeywords").val());
		window.location.href = "/regexhome/search/?k=" + escape(keyWords);
	}

	function txtFocus() {
		var keyWords = jQuery.trim($("#txtKeywords").val());
		if (keyWords == "搜索表达式..") {
			$("#txtKeywords").val("");
		}
	}

	function preserver(index, id) {
		$.ajax({
			type: "POST",
			url: "/regex/preserver",
			data: "id=" + id,
			success: function (msg) {
				if (msg == "login") {
					window.location = "/account/login";
					return;
				}
				$('#aPreserver' + index).attr("href", "javascript:void(0)");
				$('#aPreserver' + index).fadeIn();
				$('#aPreserver' + index).html("");
				$('#aPreserver' + index).removeClass().addClass("rhi_preservered");
			}
		});
	}

</script>
<h2 class="t_h2">
	浏览正则表达式
</h2>
<div class="rhi_right_content">
	<div class="rhi_categoryTitle">
		表达式分类
	</div>
	<ul class="rhi_categoryUl">
	@foreach (var item in Model.RegexCategories)
	{
		<li>
			<a href="/RegexHome/index/@item.Name/">@item.Name </a>
			<div class="rhi_categoryDescription">@item.Description</div>
		</li>
	}
	</ul>
</div>


<div class="rhi_left_content clearLeft">
	<div class="rhi_top_pagination" >
	@{
		Html.RenderPartial("/Views/Controls/Paginate.cshtml",Model.Paginate);
		int j = 0;
	}
		<div style=" float:right; width:192px;">
				<div id="search">
						<fieldset>
							<input type="text" class="clearClick" value="搜索表达式.." id="txtKeywords" onfocus="txtFocus()" />
							<a class="mcmsSearch" href="javascript:search()" id="search_go">Go</a>
						</fieldset>
				</div>
			</div>
	</div>
	<ul style="padding:0; margin:0;">
	
	@foreach (var item in Model.Expressiones)
 {

		<li>
			<div class="rhi_upup" onclick="recommend('/regex/recommend','@Model.Expressiones[j].ID','spanRecommendTimes','@j','recommendExpressionCookie','您已经推荐过此表达式,谢谢.')">
				<span @Html.Raw(string.Format("id=spanRecommendTimes{0}",j))>@(Model.Expressiones[j].Recommend == null ? "0" : Model.Expressiones[j].Recommend.Value.ToString())</span>
			</div>
			<div class="rhi_expressionContainer">
				<table>
					<colgroup>
						<col width="9%" />
						<col />
					</colgroup>
					<tr>
						<td class="rhi_tdText"></td>
						<td>
							<a href="/RegexHome/Detail/@item.ID" class="rhi_expressionTitle">@item.Title</a>
							<div style=" float:right;">
								@if (Model.RegexFavourites.FirstOrDefault(x => x.FavoriteID == item.ID)==null)
								{
									<a href="javascript:preserver(@j,'@item.ID')" class="rhi_preserver" id="aPreserver@(j)">收藏</a>
								}
								else
								{
									<a href="javascript:void(0)" class="rhi_preservered"></a>
								}
								
								<span class="rhi_byText">By:</span>
								<a href="/@item.RegexUserName" class="rhi_author" target="_blank">@item.RegexUserName</a>
								，<span class="black">@item.CreateDate.ToString("yyyy/MM/dd")</span>，
									<span class="black">浏览 - <span class="red">@(item.ClickCount==null?0:item.ClickCount)</span> </span>
							</div>
							
						</td>
					</tr>
					<tr>
						<td class="rhi_tdText"></td>
						<td>
							<div class="rhi_expressionContent">@item.Expression</div>
						</td>
					</tr>
					<tr>
						<td class="rhi_tdText">描述</td>
						<td>
							<div>@item.Description</div>
						</td>
					</tr>
					<tr>
						<td class="rhi_tdText">
							<div class="rhi_txt_matches">匹配</div>
						</td>
						<td>
							<div class="rhi_matches">
								<ul>
								 @{
	   var matches = item.Matches.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
								}
								@for (int i = 0; i < matches.Length; i++)
		{
									<li>@matches[i]</li>
		}
								</ul>
							</div>
						</td>
					</tr>
					<tr>
						<td class="rhi_tdText">
							<div class="rhi_txt_nonmatches">
								不匹配
							</div>
						</td>
						<td>
							<div class="rhi_nonmatches">
								<ul>
								 @{
		var nonMatches = item.NonMatches.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
								}
								@for (int i = 0; i < nonMatches.Length; i++)
		{
									<li>@nonMatches[i]</li>
		}
								</ul>
							</div>
						</td>
					</tr>
				</table>
			</div>
		</li>
		j++;
 }
	</ul>
	<div class="rhi_bottom_pagination" >
		@{
			Html.RenderPartial("/Views/Controls/Paginate.cshtml",Model.Paginate);
		}
	</div>
</div>

<div class="clear"></div>



